package client;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.*;

import Server.SongDTO;

public class Songs extends JFrame
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 */
	
	JPanel songs;
	JButton accept;
	
	public Songs(SongDTO[] d)
	{
		songs = new JPanel();
		accept = new JButton("Accept");
		
		this.setResizable(false);
		this.setAlwaysOnTop(true);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		songs.setLayout(new GridLayout(d.length + 2, 2));
		
		songs.add((new JLabel("Title")));
		songs.add((new JLabel("Artist")));
		
		songs.add((new JLabel("")));
		songs.add((new JLabel("")));
		
		for(int i = 0; i < d.length; i++)
		{
			try{
				SongDTO s = d[i];
				JLabel j = new JLabel(s.getTitulo());
				JLabel jj = new JLabel(s.getArtist());
				songs.add(j);
				songs.add(jj);
			}catch (Exception e) {
				System.out.println("Array de canciones vacio");
			}
			
		}
		
		this.add(songs, "Center");
		JPanel p = new JPanel();
		p.add(accept);
		this.add(p, "South");
		
		this.pack();
		//this.setSize(320, 200);
		
		accept.addActionListener(new escuchador());
	}
	
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		SongDTO[] l = new SongDTO[8];
		for(int i = 0; i < 8; i++)
		{
			SongDTO s = new SongDTO();
			s.setArtist("" + i +i + i + i);
			s.setTitulo("" + i +i + i + i);
			l[i] = s;
		}
		Songs v = new Songs(l);
		v.setVisible(true);
	}
	
	class escuchador implements ActionListener
	{

		@Override
		public void actionPerformed(ActionEvent e)
		{
			// TODO Auto-generated method stub
			if(e.getActionCommand() == "Accept")
			{
				dispose();
			}
		}
		
	}

}
